@extends('front.common.header_bg')

@section('title','企业中心')

@section('content')
@include('front.common.editor')
<link href="{{ asset('/css/employ/list.css') }}" rel="stylesheet" type="text/css">
<script src="{{ asset('/js/metisMenu/dist/metisMenu.min.js') }}"></script>
<script type="text/javascript" src="{{asset('/js/company.js')}}"></script>
<script type="text/javascript">
<!--
xweidrag();
editorInit();
//-->
</script>
<div class="main">
    <div class="employ-list clearfix" style="padding-top:30px;">
        <form id="stepForm">
        <div class="employ-list-left fl">
            <div class="employ-search">
                <div class="upload-title clearfix">
                    <a href="{{url('/company/center/document')}}"><i class="icon-angle-left"></i>&nbsp;&nbsp;返回</a>
                    <span class="float-r upload-other-step"><a href="{{url('/company/center/document/create?type=')}}"><i class="icon-plus"></i>&nbsp;&nbsp;其它教程</a></span>
                </div>
                <div class="teaches-upload-content clearfix">
                    <div class="form-group clearfix">
                        <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2">内训名称：</div>
                        <div class="col-sm-9 col-xs-12"> 
                            <input type="text" class="form-control" name="name" placeholder="请输入课程名称" value={{!empty($result)?$result->name:''}}>
                            <div class="help-block" id="error" style="color:red;"></div>
                        </div>
                     </div>
                     <div class="form-group clearfix">
                        <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2">封面图片：</div>
                        <div class="col-sm-9 col-xs-12"> 
                            <div class="input-group ">
                            	<input type="hidden" name="thumb" id="thumb" value="{{!empty($result)?$result->thumb:0}}">
                            	<input type="text" name="logo" value="{{empty($result)?'':(count($result->attachment)>0 ? $result->attachment->url:'')}}" class="form-control" autocomplete="off">
                            	<span class="input-group-btn">
                            		<button class="btn btn-default" style="height:43px;" type="button" onclick="showImageDialog(this, '{{$opts}}',{{$options}});">选择图片</button>
                            	</span>
                            </div>
                            <div class="input-group " style="margin-top:.5em;margin-left: 0px;">
                				<img src="{{empty($result)?asset('/images/nopic.jpg'):(count($result->attachment)>0 ? $result->attachment->url:'')}}" onerror="this.src='/images/nopic.jpg'; this.title='图片未找到.'" class="img-responsive img-thumbnail" width="150">
                				<em class="close" style="position:absolute; top: 0px; right: -18px;" title="删除这张图片" onclick="deleteImage(this)">×</em>
                			</div>
                        </div>
                    </div>
                     <div class="form-group clearfix">
                        <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2">课程简介：</div>
                        <div class="col-sm-9 col-xs-12"> 
                            <textarea class="form-control content" name="description" placeholder="在这里输入简介" id="description">@if(!empty($result) && !empty($result->description)){!! $result->description['name'] !!}@endif</textarea>
                            <div class="dropzone clearfix" id="desc_img_box">
                                @if(!empty($result))
                                @if(!empty($result->description['img']))
                                @foreach($result->description['img'] as $desimg)
                                @if(!empty($desimg))
                                <div class="drop-item">
                                    <img src="{{ $desimg }}"  width="100"/>
                                    <a href="javascript:void(0)" class="small-pic-del" onclick="deleteImg(this.parentNode)"><i class="icon-remove"></i></a>
                                </div>
                                @endif
                                @endforeach
                                @endif
                                @else
                                <span class="text-left">&nbsp;&nbsp;&nbsp;请将右侧图片库的图片移入此处</span>
                                @endif
                            </div>
                        </div>
                     </div>
                     <div id="tools">
                         @if(!empty($result))
                         @foreach($result->tools as $ke=>$tol)
                         <div class="form-group can-del clearfix">
                            <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2">@if($ke == 0)工具原料：@endif</div>
                            <div class="col-sm-9 col-xs-12">
                                <input type="text" class="form-control" name="tools[]" id="tools_{{$ke}}" placeholder="工具/原料" value="{{$tol}}">
                            </div>
                            @if($ke>0) <a class="delete-btn" onclick="deleteStep(this)"><i class="icon-remove"></i></a> @endif
                        </div>
                         @endforeach
                         @else
                         <div class="form-group clearfix">
                            <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2">工具原料：</div>
                            <div class="col-sm-9 col-xs-12">
                                <input type="text" class="form-control" name="tools[]" id="tools_1" placeholder="工具/原料">
                            </div>
                        </div>
                        <div class="form-group can-del clearfix">
                            <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2"></div>
                            <div class="col-sm-9 col-xs-12">
                                <input type="text" class="form-control" name="tools[]" id="tools_2" placeholder="工具/原料">
                            </div>
                            <a class="delete-btn" onclick="deleteStep(this)"><i class="icon-remove"></i></a>
                        </div>
                        @endif
                     </div>
                    <div class="form-group clearfix">
                        <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2"></div>
                        <div class="col-sm-3">
                            <button type="button" class="btn btn-default btn-block color-green" name="addmoretools" id="addmoretools"><i class="glyphicon glyphicon-plus"></i>添加工具/原料</button>
                        </div>
                    </div>
                    <div id="content-layout">
                        @if(!empty($result))
                        @if(array_key_exists('title',  $result->content[0]))
                        @foreach($result->content as $fkey=>$firstcon)
                        <div id="content_step_{{$fkey}}">
                             @foreach($firstcon['content'] as $key=>$con)
                            <div class="form-group can-del clearfix" >
                                @if($key == 0)
                                <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2">
                                    @if($firstcon['title']) {{ $firstcon['title'] }} @else 方法／步骤 @endif
                                    <i class="icon-edit" onclick="contentTitleEdit(this,'content_title_{{$fkey}}')"></i>
                                </div>
                                <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2 content_title" id="content_title_{{$fkey}}">
                                    <input type="text" class="form-control" name="content_title_{{$fkey}}" value="方法／步骤" value="{{empty($firstcon['title'])?'方法/步骤':$firstcon['title']}}">
                                </div>
                                @else
                                <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2"></div>
                                @endif
                                <div class="col-sm-9 col-xs-12">
                                    <textarea class="form-control content" name="content_step_{{$fkey}}_{{$key}}">{!! $con['name'] !!}</textarea>
                                    <div class="dropzone clearfix" id="content_step_{{$fkey}}_{{$key}}_img_box">
                                        @if(!empty($con['img']))
                                        @foreach($con['img'] as $conimg)
                                        <div class="drop-item">
                                            <img src="{{ $conimg }}" width="100"/>
                                            <a href="javascript:void(0)" class="small-pic-del" onclick="deleteImg(this.parentNode)"><i class="icon-remove"></i></a>
                                        </div>
                                        @endforeach
                                        @else
                                        <span class="text-left">&nbsp;&nbsp;&nbsp;请将右侧图片库的图片移入此处</span>
                                        @endif
                                    </div>
                                </div>
                                @if($key==0)
                                <a class="delete-btn" onclick="deleteBigStep(this)"><i class="icon-remove"></i></a>
                                @else
                                <a class="delete-btn" onclick="deleteStep(this)"><i class="icon-remove"></i></a>
                                @endif
                            </div>
                            @endforeach
                        </div>
                        <div class="form-group clearfix" >
                            <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2"></div>
                            <div class="col-sm-3">
                                <button type="button" class="btn btn-default btn-block color-green" name="addmorecontent" onclick="addMoreContent('content_step_{{$fkey}}')"><i class="glyphicon glyphicon-plus"></i>添加步骤方法</button>
                            </div>
                        </div>
                        @endforeach
                        @else
                        <div id="content_step_1">
                            @foreach($result->content as $key=>$con)
                            <div class="form-group can-del clearfix" >
                                @if($key ==0)
                                <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2">
                                    方法步骤
                                    <i class="icon-edit" onclick="contentTitleEdit(this,'content_title_1')"></i>
                                </div>
                                <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2 content_title" id="content_title_1">
                                    <input type="text" class="form-control" name="content_title_1" value="方法／步骤">
                                </div>
                                @else
                                <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2"></div>
                                @endif
                                <div class="col-sm-9 col-xs-12">
                                    <textarea class="form-control content" name="content_step_1">{!! $con['name'] !!}</textarea>
                                    <div class="dropzone clearfix" id="content_step_1_img_box">
                                        @if(!empty($con['img']))
                                        @foreach($con['img'] as $conimg)
                                        <div class="drop-item">
                                            <img src="{{ $conimg }}" width="100"/>
                                            <a href="javascript:void(0)" class="small-pic-del" onclick="deleteImg(this.parentNode)"><i class="icon-remove"></i></a>
                                        </div>
                                        @endforeach
                                        @else
                                        <span class="text-left">&nbsp;&nbsp;&nbsp;请将右侧图片库的图片移入此处</span>
                                        @endif
                                    </div>
                                </div>
                                @if($key>0)<a class="delete-btn" onclick="deleteStep(this)"><i class="icon-remove"></i></a>@endif
                            </div>
                            @endforeach
                        </div>
                        <div class="form-group clearfix" >
                            <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2"></div>
                            <div class="col-sm-3">
                                <button type="button" class="btn btn-default btn-block color-green" name="addmorecontent" id="addmorecontent"><i class="glyphicon glyphicon-plus"></i>添加步骤方法</button>
                            </div>
                        </div>
                        @endif
                        @else
                        <div id="content_step_1">
                            <div class="form-group clearfix" >
                                <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2">
                                    方法步骤
                                    <i class="icon-edit" onclick="contentTitleEdit(this,'content_title_1')"></i>
                                </div>
                                <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2 content_title" id="content_title_1">
                                    <input type="text" class="form-control" name="content_title_1" value="方法／步骤">
                                </div>
                                <div class="col-sm-9 col-xs-12">
                                    <textarea class="form-control content" name="content_step_1_1"></textarea>
                                    <div class="dropzone clearfix" id="content_step_1_1_img_box"><span class="text-left">&nbsp;&nbsp;&nbsp;请将右侧图片库的图片移入此处</span></div>
                                </div>
                            </div>
                            <div class="form-group can-del clearfix" >
                                <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2"></div>
                                <div class="col-sm-9 col-xs-12">
                                    <textarea class="form-control content" name="content_step_2"></textarea>
                                    <div class="dropzone clearfix" id="content_step_1_2_img_box"><span class="text-left">&nbsp;&nbsp;&nbsp;请将右侧图片库的图片移入此处</span></div>
                                </div>
                                <a class="delete-btn" onclick="deleteStep(this)"><i class="icon-remove"></i></a>
                            </div>
                            <div class="form-group can-del clearfix" >
                                <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2"></div>
                                <div class="col-sm-9 col-xs-12">
                                    <textarea class="form-control content" name="content_step_1_3"></textarea>
                                    <div class="dropzone clearfix" id="content_step_1_3_img_box"><span class="text-left">&nbsp;&nbsp;&nbsp;请将右侧图片库的图片移入此处</span></div>
                                </div>
                                <a class="delete-btn" onclick="deleteStep(this)"><i class="icon-remove"></i></a>
                            </div>
                        </div>
                        <div class="form-group clearfix" >
                            <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2"></div>
                            <div class="col-sm-3">
                                <button type="button" class="btn btn-default btn-block color-green" name="addmorecontent" id="addmorecontent"><i class="glyphicon glyphicon-plus"></i>添加步骤方法</button>
                            </div>
                        </div>
                        @endif
                    </div>
                    <div class="form-group clearfix">
                        <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2"></div>
                        <div class="col-sm-12 col-sm-9">
                            <button type="button" class="btn btn-default btn-block color-green" name="addnewcontent" id="addnewcontent"><i class="glyphicon glyphicon-plus"></i>添加新步骤栏目</button>
                        </div>
                    </div>
                    <div id="notices">
                        @if(!empty($result))
                         @foreach($result->notice as $keyy=>$notice)
                         <div class="form-group can-del clearfix">
                            <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2">@if($keyy == 0)注意事项：@endif</div>
                            <div class="col-sm-9 col-xs-12">
                                <input class="form-control" name="notice[]" placeholder="注意事项" id="notice_{{$keyy}}" value="{{$notice}}">
                            </div>
                            @if($keyy>0)<a class="delete-btn"  onclick="deleteStep('notice_2')"><i class="icon-remove"></i></a>@endif
                        </div>
                         @endforeach
                        @else
                        <div class="form-group can-del clearfix">
                            <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2">注意事项：</div>
                            <div class="col-sm-9 col-xs-12">
                                <input class="form-control" name="notice[]" placeholder="注意事项" id="notice_1">
                            </div>
                        </div>
                        <div class="form-group can-del clearfix">
                            <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2"></div>
                            <div class="col-sm-9 col-xs-12">
                                <input class="form-control" name="notice[]" placeholder="注意事项" id="notice_2">
                            </div>
                            <a class="delete-btn"  onclick="deleteStep('notice_2')"><i class="icon-remove"></i></a>
                        </div>
                        @endif
                     </div>
                    <div class="form-group clearfix">
                        <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2"></div>
                        <div class="col-sm-3 col-xs-12">
                            <button type="button" class="btn btn-default btn-block color-green" name="addmorenotice" id="addmorenotice" >
                                <i class="glyphicon glyphicon-plus"></i>
                                添加注意事项
                            </button> 
                        </div>
                    </div>
                     <div class="form-group clearfix">
                        <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2">作者：</div>
                        <div class="col-sm-9 col-xs-12"> 
                            <input name="author" class="form-control" type="text" value="@if(!empty($result)){{ $result->author }}@endif" />
                        </div>
                    </div>
                    <div class="form-group clearfix">
                        <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2">来源：</div>
                        <div class="col-sm-9 col-xs-12"> 
                            <input name="from" class="form-control" type="text" value="@if(!empty($result)){{ $result->from }}@endif" />
                        </div>
                    </div>
                    <div class="form-group clearfix">
                        <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2">标签：</div>
                        <div class="col-sm-9 col-xs-12"> 
                            <div class="tagsinput-primary">
                                <input name="tagsinput" class="tagsinput" data-role="tagsinput" value="@if(!empty($newstag)){{ $newstag }}@endif" />
                            </div>
                        </div>
                    </div>
                    <div class="form-group clearfix">
                        <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2">售价：</div>
                        <div class="col-sm-9 col-xs-12"> 
                            <input name="price" class="form-control" type="number" value="@if(!empty($result)){{ $result->price }}@endif" />
                        </div>
                    </div>
                </div>
                <div class="save-button-group clearfix">
                    {!! csrf_field() !!}
                    <input type="hidden" name="teaches_id" value="{{!empty($result)?$result->id:0}}">
                    <div class="form-group float-r">
                      <button type="button" class="btn btn-primary btn-upload-style" onclick="saveData('/company/center/document','stepForm','')">
                            <i class="icon-ok bigger-110"></i>完成上传
                      </button>  
                    </div>
                </div>
            </div>
        </div>
        </form>
        <div class="employ-list-right fl">
            <div class="right-drag">
                <div class="upload-drag-img">
                    <input id="uploadimg" name="uploadimg" type="file" multiple="true">
                </div>
                <div class="can-drag-img">
                    
                </div>
            </div>
        </div>
    </div>
</div>
<link rel="stylesheet" type="text/css" href="{{ asset('/js/uploadify/uploadify.css') }}">
<script src="{{ asset('/js/uploadify/jquery.uploadify.js') }}"></script>
<script src="{{ asset('js/stickUp.min.js')}}"></script>
<script type="text/javascript">
<!--
$('input').iCheck({
	checkboxClass: 'icheckbox_flat-blue',
    radioClass: 'iradio_flat-blue',
    increaseArea: '-10' // optional
});
//initiating jQuery
jQuery(function($) {
    $(document).ready( function() {
      $('.right-drag').stickUp();
    });
});

$(function(){
	/***图片上传****/
	$("#uploadimg").uploadify({
		'onInit': function () {                        //载入时触发，将flash设置到最小
            $("#uploadimg-queue").hide();
        },
	    'formData'     : {
	        'dest_dir':'teaches',
	        '_token':'{{ csrf_token() }}'
	    },
	    "width"           : 120,
	    "height"          : 33,
	    "swf"             : "{{ asset('/js/uploadify/uploadify.swf') }}",
	    "fileObjName"     : "file",
	    "buttonClass"	  : "upload-drag-img",
	    "buttonImage"     : "{{asset('/images/uploader/upload-swf-cloud.jpg')}}",
	    "buttonText"      : "上传图片",
	    "cancelImg"       : "{{asset('/js/uploadify/uploadify-cancel.png')}}",
	    "uploader"        : '/upload/images',
	    'removeTimeout'	  : 1,
	    'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
	    'onUploadSuccess':function(file, data, response){
	    	var data = eval('(' + data + ')');
            var html = '<div class="drag"><img src="'+data.url+'" width="100" /></div>';
            $('.can-drag-img').append(html);
            xweidrag();

	    }

	});
});
//-->
</script>
@stop
